<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:p="http://primefaces.prime.com.tr/ui"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:c="http://java.sun.com/jsp/jstl/core"
                template="./../templates/StakeholderPortalTemplate.xhtml">
    <ui:define name="content">
        <p:growl id="growl" showDetail="true"/>
        <h:form id="list" style="float:left; width: 250px;">
            <p:panel header="View All Table Types">
                <p:dataTable var="tableType" value="#{tableManagerBean.listOfTableType}" paginator="true" 
                             rows="10" emptyMessage="No table type added" selection="#{tableManagerBean.tableType}"
                             selectionMode="single" rowSelectListener="#{tableManagerBean.selectTable}" update="form editForm">

                    <p:column sortBy="#{tableType.name}" filterBy="#{tableType.name}">
                        <f:facet name="header">
                            <h:outputText value="Table type name" />
                        </f:facet>
                        <h:outputText value="#{tableType.name}" />
                    </p:column>
                </p:dataTable>
            </p:panel>                            
        </h:form>
        <p:accordionPanel id="accordion" style="float:left; width: 700px;" autoHeight="true">
            <p:tab id="basicInfo" title="Basic Info">
                <h:form>         
                    <h:panelGrid columns="3" columnClasses="column" cellpadding="5">   
                        <h:outputText value="Table type name: " />
                        <p:inputText required="true" requiredMessage="Table type name is required." id="tabletypename" value="#{tableManagerBean.tableType.name}">
                            <p:ajax event="blur" update="tabletypenameMsg" />
                        </p:inputText>
                        <p:message id="tabletypenameMsg" for="tabletypename" />

                        <h:outputText value="Unit capacity: " />
                        <h:selectOneMenu value="#{tableManagerBean.tableType.unitCapacity}" id="unitcapacitylist">
                            <f:selectItem itemLabel="1 person" itemValue="1"></f:selectItem>
                            <f:selectItem itemLabel="2 persons" itemValue="2"></f:selectItem>
                            <f:selectItem itemLabel="3 persons" itemValue="3"></f:selectItem>
                            <f:selectItem itemLabel="4 persons" itemValue="4"></f:selectItem>
                            <f:selectItem itemLabel="5 persons" itemValue="5"></f:selectItem>
                            <f:selectItem itemLabel="6 persons" itemValue="6"></f:selectItem>
                            <f:selectItem itemLabel="7 persons" itemValue="7"></f:selectItem>
                            <f:selectItem itemLabel="8 persons" itemValue="8"></f:selectItem>
                            <f:selectItem itemLabel="9 persons" itemValue="9"></f:selectItem>
                            <f:selectItem itemLabel="10 persons" itemValue="10"></f:selectItem>
                            <f:selectItem itemLabel="11 persons" itemValue="11"></f:selectItem>
                            <f:selectItem itemLabel="12 persons" itemValue="12"></f:selectItem>
                            <f:selectItem itemLabel="13 persons" itemValue="13"></f:selectItem>
                            <f:selectItem itemLabel="14 persons" itemValue="14"></f:selectItem>
                            <f:selectItem itemLabel="15 persons" itemValue="15"></f:selectItem>
                            <f:selectItem itemLabel="16 persons" itemValue="16"></f:selectItem>
                            <f:selectItem itemLabel="17 persons" itemValue="17"></f:selectItem>
                            <f:selectItem itemLabel="18 persons" itemValue="18"></f:selectItem>
                            <f:selectItem itemLabel="19 persons" itemValue="19"></f:selectItem>
                            <f:selectItem itemLabel="20 persons" itemValue="20"></f:selectItem>
                        </h:selectOneMenu>
                        <p:message id="unitcapacitylistMsg" for="unitcapacitylist" />

                        <h:outputText value="Description: " />
                        <p:inputTextarea required="true" requiredMessage="Description should be provided" style="width:300px;height:100px;" effectDuration="400" id="description" value="#{tableManagerBean.tableType.description}">
                            <p:ajax event="blur" update="descriptionMsg" />
                        </p:inputTextarea>    
                        <p:message id="descriptionMsg" for="description" />

                        <h:outputText value="Image display: " />
                        <p:graphicImage id="imageDisplay" value="/images/#{tableManagerBean.tableType.imageURL}"
                                        height="300" width="500"/> 
                        <p:message id="imageDisplayMsg" for="imageDisplay"/>

                        <h:outputText value="Reupload image: " />                     
                        <p:fileUpload id="imageURL" fileUploadListener="#{tableManagerBean.handleTableImageUpload}" 
                                      allowTypes="*.jpg;*.png;*.gif;" description="Images" sizeLimit="524288" update="imageDisplay">
                        </p:fileUpload>
                        <p:message id="imageURLMsg" for="imageURL"/> 

                    </h:panelGrid>
                    <p:commandButton value="Change Basic Info" update="accordion list growl" actionListener="#{tableManagerBean.editTableTypeInfo}" ajax="true"/>                               
                    <p:commandButton value="Remove" update="accordion list growl" actionListener="#{tableManagerBean.removeTableType}" ajax="true"/>                               
                </h:form>
            </p:tab>
            <p:tab title="Number of tables" id="number">
                <h:form id="form" style="float:left; width: 600px;">
                    <h:panelGrid columns="2" id="grid">
                        <h:outputLabel value="Capacity : *" for="txt_title"></h:outputLabel>
                        <p:inputText id="txt_title" 
                                     value="#{tableManagerBean.capacityControl.numberOfTable}" required="true"/>

                        <h:outputLabel value="Type:"/>
                        <h:selectOneMenu id="city" value="#{tableManagerBean.capacityControl.type}">  
                            <f:selectItems value="#{tableManagerBean.dayOfWeek}" />  
                            <p:ajax update="calendar" />  
                        </h:selectOneMenu>  

                        <h:outputLabel value="Specific Date :"/>
                        <p:calendar id="calendar" value="#{tableManagerBean.capacityControl.specificDate}" disabled="#{tableManagerBean.capacityControl.type!=8}"/>

                        <p:commandButton id="reset" value="Reset" type="reset"/>
                        <p:commandButton id="add" value="Add" update="accordion list growl"
                                         actionListener="#{tableManagerBean.addCapacityControl}" ajax="true" />
                    </h:panelGrid>

                    <p:outputPanel id="books">
                        <p:dataTable value="#{tableManagerBean.listOfCapacityControl}" var="list"
                                     rowEditListener="#{tableManagerBean.editCapacityControl}" onRowEditUpdate="panel">

                            <p:column headerText="Capacity" style="width:150px">  
                                <p:cellEditor>  
                                    <f:facet name="output">  
                                        <h:outputText value="#{list.numberOfTable}" />  
                                    </f:facet>  
                                    <f:facet name="input">  
                                        <p:inputText value="#{list.numberOfTable}" style="width:100%"/>  
                                    </f:facet>  
                                </p:cellEditor>
                            </p:column>

                            <p:column headerText="Type" style="width:150px">
                                <p:cellEditor>  
                                    <f:facet name="output">  
                                        <h:selectOneMenu value="#{list.type}" disabled="true">  
                                            <f:selectItems value="#{tableManagerBean.dayOfWeek}" />                                    
                                        </h:selectOneMenu>   
                                    </f:facet>  
                                    <f:facet name="input">  
                                        <h:selectOneMenu value="#{list.type}" >  
                                            <f:selectItems value="#{tableManagerBean.dayOfWeek}" />   
                                            <p:ajax update="calendar1" />  
                                        </h:selectOneMenu>  
                                    </f:facet>  
                                </p:cellEditor>
                            </p:column>     

                            <p:column headerText="Specific Date" style="width:150px">  
                                <p:cellEditor>  
                                    <f:facet name="output">  
                                        <p:calendar value="#{list.specificDate}" disabled="true"/>
                                    </f:facet>  
                                    <f:facet name="input">  
                                        <p:calendar id="calendar1" value="#{list.specificDate}" disabled="#{list.type!=8}"/>
                                    </f:facet>  
                                </p:cellEditor>
                            </p:column>

                            <p:column headerText="Options">  
                                <p:rowEditor/>  
                            </p:column>  
                            <p:column>
                                <f:facet name="header">
                                    <h:outputText value="Operation" />
                                </f:facet>
                                <p:commandButton value="Remove" update="accordion list growl" actionListener="#{tableManagerBean.removeCapacityControl(list.id)}" ajax="true">
                                </p:commandButton>
                            </p:column>

                        </p:dataTable>
                    </p:outputPanel>
                </h:form>
            </p:tab>
        </p:accordionPanel>
    </ui:define>
</ui:composition>
